package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.annotation.Login;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.account.UserAccount;
import com.atguigu.tingshu.vo.account.AccountLockResultVo;
import com.atguigu.tingshu.vo.account.AccountLockVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户账户管理")
@RestController
@RequestMapping("api/account/userAccount")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserAccountApiController {

    @Resource
    private UserAccountService userAccountService;

    @GetMapping("/getAvailableAmount")
    @Operation(summary = "获取用户账户余额")
    @Login(required = false)
    public Result<BigDecimal> getAvailableAmount() {
        BigDecimal availableAmount = userAccountService.getAvailableAmount();
        return Result.ok(availableAmount);
    }

    @PostMapping("checkAndLockAccount")
    @Login
    public Result<AccountLockResultVo> checkAndLockAccount(@RequestBody AccountLockVo accountLockVo) {
        AccountLockResultVo accountLockResultVo = this.userAccountService.checkAndLockAccount(accountLockVo);
        return Result.ok(accountLockResultVo);
    }
}

